<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const person = {
            name: 'jack',
            age: 21,
            language: ['java','js','css']
        };

        // 打印所有key
        console.log(Object.keys(person));
        // 打印所有value
        console.log(Object.values(person));
        // 将属性值以键值对的方式打印
        console.log(Object.entries(person));


        // 复制对象
        const target = {a:1};
        const source1 = {b:2};
        const source2 = {c:3};
        Object.assign(target, source1, source2);
        console.log(target); // {a:1, b:2, c:3}

        // 声明对象简写
        const age = 23;
        const name = "zhangsan";
        const person1 = {age: age, name: name};
        const person2 = {age, name};
        console.log(person1);
        console.log(person2);

        // 对象的函数属性简写
        let person3 = {
            name: 'jack',
            eat: function (food) {
                console.log(this.name+'正在吃'+food);
            },
            // 箭头函数中不能使用this
            eat2: food => console.log(person3.name+'正在吃'+food),
            eat3(food){
                console.log(this.name+'正在吃'+food);
            }
        }

        person3.eat('香蕉');

        person3.eat2('苹果');

        person3.eat3('梨');

        // 拷贝对象（深拷贝）
        let p1 = {name: '张三', age: 28};
        let p2 = {...p1};
        console.log(p2);

        // 对象合并
        let p3 = {name: '李四', sex: '男', birthday: '08.01'};
        // 如果合并的两个对象中有相同的属性值，后面的对象会覆盖前一个对象
        let p4 = {...p3, ...p1};
        console.log(p4);































    </script>
</body>
</html>